﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CompilerForC.SyntaxAnalysis
{
    /// <summary>
    /// Root node for all syntax nodes.
    /// </summary>
    public class SyntaxNode
    {
        #region Private Fields

        /// <summary>
        /// Id of the node. Uniquely identifies node.
        /// </summary>
        private int _id;
        /// <summary>
        /// Flag that determines is node representing terminal or non-terminal symbol.
        /// </summary>
        private bool _terminal;
        /// <summary>
        /// Value of the node.
        /// </summary>
        private string _value;

        #endregion Private Fields

        #region Public Properties

        /// <summary>
        /// Gets id that uniquely identifies node.
        /// </summary>
        public int Id
        {
            get { return _id; }
        }

        /// <summary>
        /// Gets or sets flag that indicates does this node represent terminal 
        /// or non-terminal symbol.
        /// </summary>
        public bool Terminal
        {
            get { return _terminal; }
            set { _terminal = value; }
        }

        /// <summary>
        /// Gets or sets value of the node.
        /// </summary>
        public string Value
        {
            get { return _value; }
            set { _value = value; }
        }

        #endregion Public Properties

        #region Constructor

        /// <summary>
        /// Constructs and initializes SyntaxNode.
        /// </summary>
        /// <param name="id">Id of the node.</param>
        /// <param name="terminal">True if node represents terminal symbol.</param>
        /// <param name="value">Value of the node.</param>
        public SyntaxNode(int id, bool terminal, string value)
        {
            _id = id;
            _value = value;
            _terminal = terminal;
        }

        #endregion Constructor

        #region Object Members

        /// <summary>
        /// Converts node to string.
        /// </summary>
        /// <returns>String representation of the node.</returns>
        public override string ToString()
        {
            if (_terminal)
            {
                return String.Format("{0}", _value);
            }
            else
            {
                return String.Format("<{0}>", _value);
            }
        }

        #endregion Object Members
    }
}
